#ifndef __BB_SEQUENCE_NODE_H__
#define __BB_SEQUENCE_NODE_H__

#include "../base_node.h"

namespace bb::node {

class SequenceNode : public BaseNode {
  public:
    auto Type() -> NodeType { return NodeType::Sequence; }
    auto TypeStr() -> std::string { return "Sequence"; }

    SequenceNode(std::string name) : BaseNode{name} {}

    void Init() override {}
    void Reset() override {}
    void TickSubNodes() override final {
        for (auto& [child_idx, child_node] : childs_)
            if (child_node->Status() == NodeStatus::Success)
                continue;
            else if (child_node->Status() == NodeStatus::Idle or child_node->Status() == NodeStatus::Running) {
                SetStatus(NodeStatus::Running);
                child_node->ProcessOnce();
                return;
            }
            else if (child_node->Status() == NodeStatus::Failed) {
                SetStatus(NodeStatus::Failed);
                return;
            }
            else
                throw exception::BugError("Node [", Name(), "]: child node: ", child_node->Name(),
                                          "status error:", NodeStatusToStr(child_node->Status()), " check lib code!");
        SetStatus(Success);
    }
    auto UpdateStatus() -> NodeStatus { return status_; /* too simple to update in this function, TickSubNodes already handled it */ }
};

} // namespace bb::node

#endif // __BB_SEQUENCE_NODE_H__